from . import db
import datetime


class ParkingRate(db.Model):
    __tablename__ = "li_parking_rate"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    parking = db.Column(db.String(256), doc="停车场名称")
    price = db.Column(db.Float, doc="价格", default=0)
    engineer = db.Column(db.String(64), doc="工程师")
    remarks = db.Column(db.Text, doc="备注")
    create_time = db.Column(db.DateTime, doc="创建时间", default=datetime.datetime.utcnow())
    enter_time = db.Column(db.DateTime, doc="进入时间")
    out_time = db.Column(db.DateTime, doc="出时间")
    user = db.Column(db.Integer, db.ForeignKey("li_user.id", ondelete="CASCADE"))
    car = db.Column(db.Integer, db.ForeignKey("li_car_info.id", ondelete="CASCADE"))
    deleted = db.Column(db.Boolean, default=False)
    images = db.relationship(
        "ParkingImage",
        backref="parking_rates",
        lazy="dynamic",
        passive_deletes=False,
        cascade="delete",
    )


class ParkingImage(db.Model):
    ___tablename__ = "li_parking_image"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    file = db.Column(db.String(256), default="", doc="文件")
    parking = db.Column(db.Integer, db.ForeignKey("li_parking_rate.id", ondelete="CASCADE"))
